<?php
namespace app\admin\model;
use think\Model;

class Category extends Model{
    //二级分类
    public static function category()
    {
        $list=Category::where('parentid=0')->select()->toArray();
        $cate=[];
        foreach ($list as $v){
            $cate[$v['id']]=$v;
            $cate[$v['id']]['next']=self::categorys($v['id']);
        }
        return $cate;
    }
    //无线下级级分类
    public static function categorys($id)
    {
        $list=Category::select()->toArray();
        $arr=[];
        foreach ($list as $vv){
            if ($id==$vv['parentid']){
                $arr[$vv['id']]=$vv;
                $arr[$vv['id']]['next']=self::categorys($vv['id']);
            }
        }
        return $arr;
    }
}